import Vue from 'vue'
import VueRouter from 'vue-router'
import store from '../store/store'
// import VueCookies from 'vue-cookies'
import configs from '@/configs'


//新首页
// import newHome from '../components/page/newHome/route'

Vue.use(VueRouter)
const routes = [
  { path: '/', redirect: { path: '/login' } },
  {
    path: '/login',
    component: () => import('@STmailboxes/views/login/Login')
  },
  {
    path: '/oalogin',
    component: () => import('@STmailboxes/views/oaLogin/oaLogin.vue')
  },
  // 左边菜单导航栏路由配置
  {

    path: '/index',
    component: () => import('@STmailboxes/layout/Layout.vue'),
    children: [
      {
        path: '/homePage',
        component: () => import('@STmailboxes/views/homePage/homePage.vue'),
        name: '首页',
        meta: {
          title: '首页',
        }
      },
      {
        path: '/letter',
        component: () => import('@STmailboxes/views/letter/letter.vue'),
        name: '信件管理',
        meta: {
          title: '信件管理',
        }
      },
      {
        path: '/system',
        component: () => import('@STmailboxes/views/system/system.vue'),
        name: '系统管理',
        meta: {
          title: '系统管理',
        }
      },
      {
        path: '/info',
        component: () => import('@STmailboxes/views/info/info.vue'),
        name: '消息管理',
        meta: {
          title: '消息管理',
        }
      },

    ]
  },

  // 404界面（必须放置在路由最底部）
  {
    path: '*',
    component: () => import(/* webpackChunkName: "notFound" */ '@/components/notFound.vue')
  }
]

const router = new VueRouter({
  mode: 'history',
  base: configs.BASE_URL,
  // base: '/',
  routes
})
// 页面跳转回到最顶部
router.afterEach((to, from, next) => {
  window.scrollTo(0, 0)
})

router.beforeEach((to, from, next) => {
  const whiteList = ['/login', '/oalogin'] //路由白名单
  const token = sessionStorage.getItem('authorization_Ygd')
  // if (!whiteList.includes(to.path) && !token) {
  //   next({ path: "/login" });
  // } else {
  //   next();
  // }
  next();
  if (to.query.title != null) {
    to.meta.title = to.query.title
  }
  store.commit('setTreeName', '')
  next()
});
export default router
